package 牛客_面试必刷.Month07.day08;

public class 判断链表中是否有环 {
    public boolean hasCycle(ListNode head) {
        //真的就是太久没有做了，要好好的再看一遍
        if(head == null) return false;
        ListNode fast = head;
        ListNode slow = head;
        while(fast != null && fast.next != null){
            fast = fast.next.next;
            slow = slow.next;
            if(fast == slow) return true;
        }
        return false;
    }
}
